#! /usr/bin/env python
# -*- coding: utf8 -*-

import cElementTree as et
import sys

if len(sys.argv) != 4:
    print "Adds an element between the root node and each of its child nodes, thus"
    print "making it easier to apply certain transformations by [ms]XML."
    print "To remove those roots, use the cut_roots.py"
    print "Usage: %s <in file> <element name> <out file>" % (sys.argv[0])
    
    sys.exit()
    
element_tree = et.parse(sys.argv[1])
root_element = element_tree.getroot()

children = root_element.getchildren()

for i in children:
    new_element = et.Element(sys.argv[2])
    root_element.append(new_element)
    root_element.remove(i)
    new_element.append(i)
    
element_tree.write(file=sys.argv[3])
